feat(optimizer): Implement LIKE expression rule for query optimization#96
feat(optimizer): Implement LIKE expression rule for query optimization#96loloxwg wants to merge 10 commits intoKipData:mainfrom
Conversation
The commit introduces a new rule for the optimization of LIKE operator in SQL queries. The LIKE operator expressions are rewritten to make use of binary operators such as GtEq and Lt in certain cases which enhances the performance of queries. Additionally, new tests for incremented character rule have been added, and `LikeRewrite` has been added to optimizer rules in the rule set.
src/optimizer/rule/simplification.rs
Outdated
| { | ||
| // if left is column and right is constant | ||
| if let ScalarExpression::ColumnRef(_) = left_expr.as_ref() { | ||
| if let ScalarExpression::Constant(value) = right_expr.as_ref() { |
There was a problem hiding this comment.
reduce unnecessary nesting and matching
if let ScalarExpression::Constant(DataValue::Utf8(mut val)) = right_expr.as_ref() {
|
It looks good, but it lacks the test of the rules. Reference: https://github.com/KipData/KipSQL/blob/main/src/optimizer/rule/column_pruning.rs#L166 |
| } | ||
|
|
||
| fn apply(&self, node_id: HepNodeId, graph: &mut HepGraph) -> Result<(), OptimizerError> { | ||
| if let Operator::Filter(mut filter_op) = graph.operator(node_id).clone() { |
There was a problem hiding this comment.
Use the operator_mut method to modify directly instead of replace
| ty, | ||
| } = filter_op.predicate.clone() | ||
| { | ||
| if let ScalarExpression::Constant(value) = right_expr.as_ref() { |
There was a problem hiding this comment.
if let ScalarExpression::Constant(DataValue::Utf8(Some(value))) = right_expr.as_mut()
Instead of pattern matching layer by layer again
| ty: LogicalType, | ||
| filter_op: &mut FilterOperator, | ||
| ) { | ||
| value_str.map(|value_str| { |
There was a problem hiding this comment.
Method encapsulation of little significance, just to collapse the nesting
| ) { | ||
| value_str.map(|value_str| { | ||
| if value_str.ends_with('%') { | ||
| let left_bound = value_str.trim_end_matches('%'); |
There was a problem hiding this comment.
if let Some(right_bound) = increment_last_char(left_bound) {
filter_op.predicate = Self::create_new_expr(
&mut left_expr.clone(),
ty,
left_bound.to_string(),
right_bound,
);
}| left_bound: String, | ||
| right_bound: String, | ||
| ) -> ScalarExpression { | ||
| let new_expr = ScalarExpression::Binary { |
There was a problem hiding this comment.
Meaningless variable declaration -> new_expr
|
|
||
| #[test] | ||
| fn test_increment_char() { | ||
| assert_eq!(increment_last_char("abc"), Some("abd".to_string())); |
There was a problem hiding this comment.
There are too few test cases and there is no test carry situation
The commit introduces a new rule for the optimization of LIKE operator in SQL queries. The LIKE operator expressions are rewritten to make use of binary operators such as GtEq and Lt in certain cases which enhances the performance of queries. Additionally, new tests for incremented character rule have been added, and
LikeRewritehas been added to optimizer rules in the rule set.What problem does this PR solve?
Add corresponding issue link with summary if exists -->
Issue link:
What is changed and how it works?
Code changes
Check List
Tests
Side effects
Note for reviewer